package cn.chenfeifx.checker;

import cn.chenfeifx.checker.eneity.ExportDataModel;
import cn.chenfeifx.checker.eneity.MessageEntity;
import cn.chenfeifx.checker.eneity.Report;
import cn.chenfeifx.core.common.ResourcesLoader;
import cn.chenfeifx.core.controls.CFHeader;
import cn.chenfeifx.core.controls.CFStage;
import cn.chenfeifx.checker.ui.Index;
import cn.chenfeifx.core.controls.CFTableView;
import javafx.application.Application;
import javafx.application.HostServices;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CheckerApp extends Application {

    public static HostServices hostServices;

    private static CheckerApp instance;

    private Map<String,List<MessageEntity>> messageList = new ConcurrentHashMap<String,List<MessageEntity>>();

    private Map<String,List<ExportDataModel>> reports = new ConcurrentHashMap<String,List<ExportDataModel>>();

    private CFTableView cfTableView = new CFTableView();


    private CFTableView cfTableView2 = new CFTableView();


    public List<ExportDataModel> getReports(String type) {
        return reports.get(type);
    }

    public void setReport(String type, ExportDataModel exportDataModel) {
        List<ExportDataModel> exportDataModels = reports.get(type);
        if(exportDataModels == null || exportDataModels.isEmpty()){
            exportDataModels = new ArrayList<>();
            exportDataModels.add(exportDataModel);
        }else {
            exportDataModels.add(exportDataModel);
        }
        reports.put(type,exportDataModels);
    }

    public void setReports(String type,List<ExportDataModel> reports) {
        this.reports.put(type,reports);
    }

    public CFTableView getCfTableView() {
        return cfTableView;
    }

    public CFTableView getCfTableView2(){
        return cfTableView2;
    }

    public void setCfTableView(CFTableView cfTableView) {
        this.cfTableView = cfTableView;
    }

    public void setCfTableView2(CFTableView cfTableView){
        this.cfTableView2=cfTableView;
    }

    public List<MessageEntity> getMessageList(String type) {
        return messageList.get(type);
    }

    public void setMessageList(String type,List<MessageEntity> messageList) {
        List<MessageEntity> messageEntities = this.messageList.get(type);
        if(messageEntities != null){
            messageEntities.addAll(messageList);
            this.messageList.put(type,messageEntities);
        }else {
            this.messageList.put(type, messageList);
        }
    }

    public static CheckerApp getInstance() {
        return instance;
    }

    @Override
    public void init() throws Exception {
        super.init();
        instance = this;
    }

    @Override
    public void start(Stage primaryStage) {
        hostServices = getHostServices();

        //基础尺寸
        CFStage stage = new CFStage(new Index())
                .setHeaderStyle(CFHeader.HeaderStyle.CLOSE)
                .setBackdropImage(ResourcesLoader.loadFxImage("/img/backdrop2.jpg"));
        stage.show();
        stage.setMaximized(true);
    }
}